[<<Previous Entry]
[^^Up^^]
[Next Entry>>]
[Menu]
[About The Guide]
matherr() Handle Math Error
#include <math.h>
int matherr(x);
struct exception *x; Math exception information
matherr() is called when errors are detected by the math functions.
(See the individual math functions for specific information on when
matherr() is called.) A program can supply its own matherr()
function to provide special error handling.
When an error in a math function occurs, matherr() is called with a
pointer to an exception structure, 'x', that holds the error
information. The structure 'exception' is defined in math.h as:
struct exception
{
int type; /* type of math error */
char *name; /* name of function causing error */
double arg1, arg2; /* argument(s) of math function */
double retval; /* default error return value */
};
'type' specifies the type of math error and is one of the following
values (defined in <math.h>):
DOMAIN Argument domain error
SING Argument singularity
OVERFLOW Overflow range error
UNDERFLOW Underflow range error
TLOSS Total loss of significance
'name' is a pointer to a null-terminated string containing the name
of the math function that caused the error; 'arg1' and 'arg2' (if the
function accepts two arguments) are the argument(s) that caused the
error; and 'retval' is the value that will be returned by the
function for this error. 'retval' may be changed by matherr(), thus
changing the value that will be returned by the math function. (Be
careful: The return value is used to specify that an error
occurred.)
matherr() returns 0 to indicate that an error still exists. In this
case, the math function will print any error messages to 'stderr' and
set 'errno' (defined in errno.h) to the appropriate error value.
matherr() returns a non-zero value to indicate that the error has
been corrected. In this case, the function should suppress error
messages and should not set 'errno'.
Returns: 0 to indicate that the error still exists and
non-zero to indicate that the error has been
corrected.
Notes: The default matherr() error handler just returns 0.
The following functions call matherr(): acos, asin,
atan, atan2, cabs, cos, cosh, exp, frexp, hypot,
ldexp, log, log10, pow, pow10, sin, sinh, sqrt, tan,
and tanh.
This page created by ng2html v1.05, the Norton guide to HTML conversion utility.
Written by Dave Pearson